//
//  VistaAcercaDe.m
//  Pico y placa
//
//  Created by Mario Franco on 1/9/13.
//  Copyright (c) 2013 Mario Franco. All rights reserved.
//

#import "VistaAcercaDe.h"
#import <QuartzCore/QuartzCore.h>


@interface VistaAcercaDe ()

@end

@implementation VistaAcercaDe
@synthesize bannerView;
@synthesize subvista1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self moveBannerViewOffscreen];
    
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)descartarVista:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)moveBannerViewOffscreen
{
    //Hacer que la subvista1 ocupe el espacio dejado por el bannerView
    CGRect frameOriginalSubvista1 = subvista1.frame;
    CGFloat nuevoHeight = self.view.frame.size.height;
    CGRect frameNuevoSubvista1 = frameOriginalSubvista1;
    frameNuevoSubvista1.size.height = nuevoHeight;
    
    //Posicionar el bannerView debajo de la subvista1 (offscreen)
    CGRect frameNuevoBanner = bannerView.frame;
    frameNuevoBanner.origin.y = nuevoHeight;
    
    subvista1.frame = frameNuevoSubvista1;
    bannerView.frame = frameNuevoBanner;
}

-(void)moveBannerViewOnscreen
{
    CGRect frameNuevoBanner = bannerView.frame;
    frameNuevoBanner.origin.y = self.view.frame.size.height - frameNuevoBanner.size.height;
    
    CGRect frameOriginalSubvista1 = subvista1.frame;
    CGFloat nuevoHeight = self.view.frame.size.height - frameNuevoBanner.size.height;
    CGRect frameNuevoSubvista1 = frameOriginalSubvista1;
    frameNuevoSubvista1.size.height = nuevoHeight;
    
    [UIView beginAnimations:@"BannerViewIntro" context:NULL];
    subvista1.frame = frameNuevoSubvista1;
    bannerView.frame = frameNuevoBanner;
    [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    [self moveBannerViewOffscreen];
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    [self moveBannerViewOnscreen];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [bannerView removeFromSuperview];
    bannerView.delegate = nil;
    bannerView = nil;
}
@end
